<template>
<h2>添加会员信息</h2>

<table border="1">
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" v-model="info.M_Name"/>
        </td>
    </tr>
    <tr>
        <td>密码:</td>
        <td>
            <input type="password" v-model="info.M_Pwd"/>
        </td>
    </tr>
    <tr>
        <td>真实姓名:</td>
        <td>
            <input type="text" v-model="info.M_TrueName">
        </td>
    </tr>
    <tr>
        <td>电话:</td>
        <td>
            <input type="text" v-model="info.M_Phone"/>
        </td>
    </tr>
    <tr>
        <td>状态</td>
        <td>
            <input type="radio" v-model="info.M_State" :value="true">启用
            <input type="radio" v-model="info.M_State" :value="false">禁用
        </td>
    </tr>
    <tr>
        <td>会员类型编号:</td>
        <td>
            <select v-model="info.MT_Id">
                <option :value="0">--请选择--</option>
                <option v-for=" item in MemberTypeInfo" :value="item.Id">{{ item.MT_Name }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="添加" @click="SaveData"/>
        </td>
    </tr>
</table>

</template>
<script setup lang="ts">

import { onMounted,ref } from 'vue';
import axios from 'axios';


const MemberTypeInfo=ref([{

    Id:0,
    MT_Name:""
}]);


const info=ref({
    M_Name:"",

    M_TrueName:"",

    M_Pwd:"",

    M_Phone:"",

    M_State:true,
    MT_Id:0
})


const SaveData=()=>{

if(info.value.M_Name==""){

    alert("用户名不能为空");
    return;
}


axios.post('https://localhost:7083/api/Member/AddMember',info.value)
.then(res=>{
console.log(res.data);
if(res.data>0){
    console.log(res.data)
    alert("添加成功");
}
else if(res.data==-1){
alert("用户已经存在");

}
else{
    alert("添加失败");
}

})


}

onMounted(()=>{
    LoadType();
})

const LoadType=()=>{

axios.get('https://localhost:7083/api/Member/GetTypes')
.then(res=>{
    MemberTypeInfo.value=res.data;
})

}



</script>